import 'dart:io';

import 'package:device_info_plus/device_info_plus.dart';

class DeviceInfoManager {
  static String? platformName;
  static String? deviceModel;
  static String? osName;
  static String? osVersion;
  static String? appVersion;
  static String? rawModel;

  static Future<void> init() async {
    final deviceInfo = DeviceInfoPlugin();

    if (Platform.isAndroid) {
      final androidInfo = await deviceInfo.androidInfo;
      platformName = 'ANDROID';
      deviceModel = androidInfo.model;
      osName = 'Android';
      osVersion = androidInfo.version.release;
    } else if (Platform.isIOS) {
      final iosInfo = await deviceInfo.iosInfo;
      platformName = 'APPLE';
      deviceModel = iosInfo.utsname.machine;
      rawModel = iosInfo.model;
      osName = iosInfo.systemName;
      osVersion = iosInfo.systemVersion;
    }

    // final packageInfo = await PackageInfo.fromPlatform();
    // appVersion = packageInfo.version;
  }

  /// 判断是否为 iPhone SE 系列（简单基于机型标识）
  static Future<bool> isiPhoneSE() async {
    if (!Platform.isIOS) return false;
    // 确保已初始化
    if (deviceModel == null) {
      await init();
    }
    const seModels = {
      'iPhone8,4', // iPhone SE (1st gen)
      'iPhone12,8', // iPhone SE (2nd gen)
      'iPhone14,6', // iPhone SE (3rd gen)
    };
    return seModels.contains(deviceModel);
  }
}
